package com.example.yuejian.yuejian.fragment;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.example.yuejian.yuejian.R;
import com.example.yuejian.yuejian.adapter.TrainTypeAdapter;
import com.example.yuejian.yuejian.base.ModleListListener;
import com.example.yuejian.yuejian.bean.Train;
import com.example.yuejian.yuejian.model.TrainModel;

import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class TrainAllFragment extends Fragment {

    private RecyclerView recyclerView;
    private View view;
    List<Train> list;
    private ModleListListener<Train>listListener=new ModleListListener<Train>() {
        @Override
        public void onResponse(List<Train> l) {
            list=l;
            recyclerView.setAdapter(new TrainTypeAdapter(getActivity(),list));
        }

        @Override
        public void onFail(String msg) {
            Toast.makeText(getActivity(),"网络错误",Toast.LENGTH_SHORT).show();
        }
    };

    public TrainAllFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        view= inflater.inflate(R.layout.fragment_train_all, container, false);
        initViews();
        getDatas();
        return view ;
    }
    private void initViews()
    {
        recyclerView=(RecyclerView)view.findViewById(R.id.train_all_recycleview);
        // GridLayoutManager gm = new GridLayoutManager(this.getActivity(),2);
        // 网格是的list布局   2列
        recyclerView.setLayoutManager(new LinearLayoutManager(this.getActivity()));
        //recyclerView.setLayoutManager(gm););

    }
    private void getDatas()
    {
        TrainModel model=new TrainModel();
        model.TrainAllList(listListener);
    }

}
